package com.cloud.lawcase.common.utils;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.springframework.util.StringUtils;

import com.aspose.words.Document;
import com.aspose.words.DocumentBuilder;
import com.aspose.words.Node;
import com.aspose.words.Paragraph;

public class WordHelper {
	
	/**
	 * 读取word文件流中的段落
	 * @param in
	 * @return
	 */
	public static List<String> readWordParagraph(InputStream in) {
		Document doc;
		try {
			doc = new Document(in);
			DocumentBuilder builder = new DocumentBuilder(doc);
			boolean b = true;
			List<String> content = new ArrayList<String>();
			while (b) {
				Paragraph p = builder.getCurrentParagraph();
				String text = p.getText();
				if (!StringUtils.isEmpty(text) && ChineseHelper.includeChinese(text)) {
					content.add(text.trim());
				}
				Node node = p.getNextSibling();
				if (null == node) {
					b = false;
				} else {
					builder.moveTo(node);
				}
			}
			return content;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}
